
const book = { 
    state: { 
        fileName: '',
        currentBook: '',//当前打开的电子书
        menuVisible: false,
        settingVisible: -1,/*设置显示选择，-1:不显示，0：显示字号选择，1:主题 ，2：进度， 3：目录*/
        defaultFontSize: '16',    
        defaultFontFamily: 'Default', 
        fontFamilyVisible: false,//字体选择的弹出框
        defaultTheme: 'Default',     
        bookAvailable: false,
        progress: 0,       
        section: 0,
        navigation: null,            
    },
    getters: { 
        //方便用 mapGetters 混入 
        fileName: state => state.fileName,
        currentBook: state => state.currentBook,
        menuVisible: state => state.menuVisible,
        settingVisible: state => state.settingVisible,
        defaultFontSize: state => state.defaultFontSize,
        fontFamilyVisible: state => state.fontFamilyVisible,
        defaultFontFamily: state => state.defaultFontFamily,
        defaultTheme: state => state.defaultTheme,
        bookAvailable: state => state.bookAvailable,
        progress: state => state.progress,
        section: state => state.section,
        navigation: state => state.navigation
    },
    mutations: { 
        'SET_FILENAME':(state,fileName) => { 
            state.fileName = fileName
        },
        'SET_CURRENT_BOOK':(state,currentBook) => { 
            state.currentBook = currentBook
        },
        'SET_MENU_VISIBLE':(state,visible) => { 
            state.menuVisible = visible
        },
        'SET_SETTING_VISIBLE':(state,visible) => { 
            state.settingVisible = visible
        },
        'SET_DEFAULT_FONT_SIZE':(state,fontSize) => { 
            state.defaultFontSize = fontSize
        },
        'SET_FONT_FAMILY_VISIBLE': (state,visible) => { 
            state.fontFamilyVisible = visible
        },
        'SET_DEFAULT_FONT_FAMILY': (state, font) => {
            state.defaultFontFamily = font
        },
        'SET_DEFAULT_THEME': (state, theme) => { 
            state.defaultTheme = theme
        },
        'SET_BOOK_AVAILABLE': (state, bookAvailable) => { 
            state.bookAvailable = bookAvailable
        },
        'SET_PROGRESS': (state, progress) => { 
            state.progress = progress
        },
        'SET_SECTION': (state, section) => { 
            state.section = section
        },
        'SET_NAVIGATION': (state, navigation) => {
            state.navigation = navigation
        },
    },
    actions: { 
        setFileName: ({commit},fileName) => { 
            return commit('SET_FILENAME',fileName)
        },
        setCurrentBook: ({commit},book) => { 
            return commit('SET_CURRENT_BOOK',book)
        },
        setMenuVisible: ({commit},visible) => { 
            return commit('SET_MENU_VISIBLE',visible)
        },
        setSettingVisible: ({commit},visible) => { 
            return commit('SET_SETTING_VISIBLE',visible)
        },
        setDefaultFontSize: ({commit},fontSize) => { 
            return commit('SET_DEFAULT_FONT_SIZE',fontSize)
        }, 
        setFontFamilyVisible: ({commit},visible) => { 
            return commit('SET_FONT_FAMILY_VISIBLE',visible)
        },
        setDefaultFontFamily: ({ commit }, font) => {
            return commit('SET_DEFAULT_FONT_FAMILY', font)
        },
        setDefaultTheme: ({ commit }, theme) => { 
            return commit('SET_DEFAULT_THEME',theme)
        },
        setBookAvailable: ({ commit }, bookAvailable) => { 
            return commit('SET_BOOK_AVAILABLE', bookAvailable)
        },
        setProgress: ({ commit }, progress) => { 
            return commit('SET_PROGRESS', progress)
        },
        setSection: ({ commit }, section) => {
            return commit('SET_SECTION', section)
        },
        setNavigation: ({ commit }, navigation) => {
            return commit('SET_NAVIGATION', navigation)
        },
    }
}

export default book;